package com.zxf.crypt.advice;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpInputMessage;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

/**
 * 请求数据解密
 *
 * @author zxf
 **/
public class DecryptHttpInputMessage implements HttpInputMessage {

    private final HttpInputMessage inputMessage;
    private final String deData;

    public DecryptHttpInputMessage(HttpInputMessage inputMessage, String deData) {
        this.inputMessage = inputMessage;
        this.deData = deData;
    }

    @Override
    public InputStream getBody() {
        return new ByteArrayInputStream(this.deData.getBytes(StandardCharsets.UTF_8));
    }

    @Override
    public HttpHeaders getHeaders() {
        return this.inputMessage.getHeaders();
    }
}